feat:Add MCPToolFilter schema and extend MCP server invocation fields#214
feat:Add MCPToolFilter schema and extend MCP server invocation fields#214
Conversation
WalkthroughIntroduces MCPToolFilter as a reusable schema and replaces prior inline tool filter definitions. Extends the MCP server invocation schema with authorization, connector_id, and headers. Adjusts required properties to allow either server_url or connector_id. Updates references for tool approval sections to use MCPToolFilter and refreshes descriptions. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant API as OpenAI-Compatible API
participant Connector as Connector Service
participant MCP as MCP Server
Client->>API: Invoke MCP (server_label, type, server_url? / connector_id?, headers?, authorization?, tool_filter?)
Note over API: Validate: require one of server_url or connector_id<br/>Validate MCPToolFilter schema (read_only, tool_names)
alt Using connector_id
API->>Connector: Connect(connector_id, auth token, headers)
Connector->>MCP: Resolve/Route to service-specific MCP endpoint
else Using server_url
API->>MCP: Connect(server_url, headers, auth token)
end
API->>Client: Response / errors (validation, connectivity)
Note over API,MCP: Tool approvals reference MCPToolFilter for allow/deny
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/libs/tryAGI.OpenAI/openapi.yaml (3)
17744-17755: Future-proof connector_id or document update cadenceHard-coding an enum of connector IDs is fine for strong validation, but it will break clients when new connectors ship. Either:
- Document that this enum will evolve and may require frequent client updates, or
- Switch to a relaxed validation (e.g., pattern: '^connector_[a-z0-9]+$') and move the known set to docs.
Example diff for the relaxed approach:
- connector_id: - enum: - - connector_dropbox - - connector_gmail - - connector_googlecalendar - - connector_googledrive - - connector_microsoftteams - - connector_outlookcalendar - - connector_outlookemail - - connector_sharepoint - type: string + connector_id: + type: string + pattern: '^connector_[a-z0-9]+$'
17765-17773: Approval object semantics: precedence and completeness checksGood move to reuse MCPToolFilter via $ref for always/never. Two follow-ups:
- Define precedence if a tool matches both always and never (e.g., never overrides always).
- Ensure the alternate string enum path includes both 'always' and 'never' (the snippet shows only 'always').
Proposed doc tweak:
description: "Specify which of the MCP server's tools require approval. Can be -`always`, `never`, or a filter object associated with tools +`always`, `never`, or an object with `always`/`never` filters. If a tool matches both, +`never` takes precedence. This setting determines which tools require user approval that require approval.\n"Please confirm that the accompanying string variant enum includes both:
- always
- never
17834-17848: MCPToolFilter: add constraints and clarify AND/OR semanticsThe schema looks good. Two refinements:
- Enforce uniqueness and non-empty tool_names.
- Clarify whether multiple fields are combined with AND (recommended) or OR when both are provided.
Apply:
MCPToolFilter: title: MCP tool filter type: object properties: read_only: type: boolean description: "Indicates whether or not a tool modifies data or is read-only. If an MCP server is [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint), it will match this filter.\n" tool_names: title: MCP allowed tools type: array items: type: string - description: List of allowed tool names. + description: List of allowed tool names. + minItems: 1 + uniqueItems: true additionalProperties: false - description: "A filter object to specify which tools are allowed.\n" + description: "A filter object to specify which tools are allowed. When multiple fields are provided, they are combined with logical AND."Defining this as a reusable schema is a solid improvement in consistency.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (13)
src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI..JsonSerializerContext.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.JsonConverters.MCPToolConnectorId.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.JsonConverters.MCPToolConnectorIdNullable.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.JsonSerializerContextTypes.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPTool.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPToolConnectorId.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPToolFilter.Json.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPToolFilter.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPToolRequireApprovalEnum.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPToolRequireApprovalEnumAlways.Json.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPToolRequireApprovalEnumAlways.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPToolRequireApprovalEnumNever.Json.g.csis excluded by!**/generated/**src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.Models.MCPToolRequireApprovalEnumNever.g.csis excluded by!**/generated/**
📒 Files selected for processing (1)
src/libs/tryAGI.OpenAI/openapi.yaml(4 hunks)
🔇 Additional comments (2)
src/libs/tryAGI.OpenAI/openapi.yaml (2)
17735-17741: No invalid union here:anyOfalready wraps the array and the filter objectThe snippet around lines 17735–17741 shows you’re using an
anyOfcomposition onallowed_tools, which is valid OpenAPI 3.x syntax and will be accepted by standard validators. The original comment—which assumed a bare array followed by a dangling$ref—doesn’t match the current code.• The union is correctly modelled under
anyOf:allowed_tools: anyOf: - title: MCP allowed tools type: array items: type: string description: A string array of allowed tool names - $ref: '#/components/schemas/MCPToolFilter' description: "List of allowed tool names or a filter object.\n" nullable: true• If you need exclusive “either array or object” semantics, you may opt to replace
anyOfwithoneOf. Otherwise, no change is needed.Please disregard the original suggestion to “add a oneOf around array vs. MCPToolFilter,” since the schema is already valid as written.
Likely an incorrect or invalid review comment.
17786-17792: Indentation Verified: oneOf aligns with schema‐level keys
The parent schema’s keys (type,properties,description) are indented 6 spaces. The proposedoneOf:block also uses 6 spaces, so it will be placed correctly at the schema level.
No linter errors are expected when applying the patch as-is.
| authorization: | ||
| type: string | ||
| description: "An OAuth access token that can be used with a remote MCP server, either \nwith a custom MCP server URL or a service connector. Your application\nmust handle the OAuth authorization flow and provide the token here.\n" | ||
| connector_id: |
There was a problem hiding this comment.
🛠️ Refactor suggestion
authorization should be writeOnly and clarified vs. headers.Authorization
Storing raw access tokens in a data object is acceptable here, but:
- Mark it writeOnly to avoid accidental echoes in responses.
- Clarify precedence if both this field and headers.Authorization are supplied.
Apply:
authorization:
type: string
- description: "An OAuth access token that can be used with a remote MCP server, either
+ writeOnly: true
+ minLength: 1
+ description: "An OAuth access token that can be used with a remote MCP server, either
with a custom MCP server URL or a service connector. Your application
must handle the OAuth authorization flow and provide the token here.
+If both this field and `headers.Authorization` are present, `authorization` takes precedence."🤖 Prompt for AI Agents
In src/libs/tryAGI.OpenAI/openapi.yaml around lines 17741 to 17744, the schema's
authorization field needs to be marked writeOnly and its description updated to
clarify precedence versus headers.Authorization; change the field to include
writeOnly: true and update the description to state that this token will not be
returned in responses and that if both this authorization field and
headers.Authorization are provided, headers.Authorization takes precedence (or
vice versa depending on desired behavior), so callers know which value will be
used. Ensure the OpenAPI description explicitly documents the precedence and
that writeOnly is applied so tools and responses won't echo the token.
| headers: | ||
| type: object | ||
| additionalProperties: |
There was a problem hiding this comment.
💡 Verification agent
❓ Verification inconclusive
headers.additionalProperties has no schema value (invalid in OAS)
additionalProperties is present but empty. OpenAPI requires a boolean or a schema. This will fail validation.
Apply:
headers:
type: object
- additionalProperties:
+ additionalProperties:
+ type: string
+ description: "Arbitrary HTTP headers to include when calling the MCP server."Optional: Document that header names are case-insensitive and will be canonicalized by the client.
Re-run the validator after this change (see previous script).
Critical: Define a schema for headers.additionalProperties
OpenAPI requires that additionalProperties be either a boolean or a Schema Object (it cannot be left empty). An empty additionalProperties: is treated as a null value, which will fail OpenAPI validation.
Please apply the following change to ensure headers may safely accept arbitrary string‐valued headers:
• File: src/libs/tryAGI.OpenAI/openapi.yaml
• Around lines ~17756
headers:
type: object
- additionalProperties:
+ additionalProperties:
+ type: string
+ description: "Arbitrary HTTP headers to include when calling the MCP server."Optional nit: note in your docs that header names are case-insensitive and will be canonicalized by the client.
After applying this change, re-run your OpenAPI validator to confirm the schema is now valid.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| headers: | |
| type: object | |
| additionalProperties: | |
| headers: | |
| type: object | |
| additionalProperties: | |
| type: string | |
| description: "Arbitrary HTTP headers to include when calling the MCP server." |
🤖 Prompt for AI Agents
In src/libs/tryAGI.OpenAI/openapi.yaml around lines 17756-17758 the headers
object currently has an empty additionalProperties entry which is invalid;
update it so additionalProperties is a Schema Object that allows arbitrary
string-valued header entries (e.g. set additionalProperties to a schema with
type: string and optional description), add an optional note in the headers
description that header names are case-insensitive and will be canonicalized by
the client, and re-run the OpenAPI validator to confirm the schema is valid.
Summary by CodeRabbit